package com.qf.controller.manager;

import com.github.pagehelper.PageInfo;
import com.qf.entitys.Order;
import com.qf.entitys.RespBean;
import com.qf.service.OrderService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/manager/order")
public class OrderController {
    @Resource
    private OrderService service;

    @GetMapping("/list")
    public String orderList(Integer pageindex, HttpServletRequest request,Order order){
        PageInfo<Order> pageInfo = service.selectPayBusiness(order,pageindex);
        request.setAttribute("pageInfo",pageInfo);
        request.setAttribute("outTradeNo",order.getOutTradeNo());
        request.setAttribute("orderType",order.getOrderType());

        return "manager/orderList";
    }

    @GetMapping("/del")
    @ResponseBody
    public RespBean del(String id){
        Order order=new Order();
        order.setOutTradeNo(id);
        try {
            order.setOrderType(7);
            int i = service.updateByPrimaryKeySelective(order);
            if (i>0){
                return RespBean.success("删除成功");
            }else {
                return RespBean.error("删除失败");
            }
        }catch (Exception ex){
            return RespBean.error("删除失败");
        }
    }
}
